import tensorflow as tf

with tf.device("cpu"):
    a = tf.constant([1])
print(a.device)